<template ref="datadictForm">
  <div class="app-container">
    <el-form :model="queryParams2" ref="queryForm2" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item v-if="hisVersionVal" label="版本号" prop="hisVersionVal">
        <el-input disabled="true"
                  v-model="queryParams2.hisVersionVal"
                  placeholder="请输入版本号"
                  clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
    </el-form>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="键值代码" prop="keyId">
        <el-input
          v-model="queryParams.keyId"
          placeholder="请输入键值代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="键值名称" prop="keyName">
        <el-input
          v-model="queryParams.keyName"
          placeholder="请输入键值名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border="border" v-loading="loading" :data="datadictList" max-height="550px"
              @selection-change="handleSelectionChange"
              @sort-change="handleSortChange" :row-style="tableRowStyle">
      <el-table-column label="分类代码"  align="center" width="180" prop="classId" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="分类名称" align="center" width="200" prop="className" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="分类英文名" align="center" width="200"  prop="classEname" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="键值代码" align="center" width="180"  prop="keyId" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="键值名称" align="center" width="180" prop="keyName" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="英文名称" align="center" width="180" prop="keyEname" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="是否有效"  width="200" align="center" prop="orValidD" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="备注说明" align="center" width="200" prop="memo" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="时间标识" align="center" prop="timeMark" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeMark) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否启用" width="180" align="center" prop="sta" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="顺序" align="center" prop="keySeq" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="创建人" width="180" align="center" prop="createPrsn" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" width="180"  align="center" prop="updatePrsn" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否已删除" align="center" width="180" prop="fdeleteId" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listDatadict} from "@/api/reportworld/datadict";
import { getTableRowStyle } from "@/utils/yss";
export default {
  name: "DataDict",
  props :["classId","hisVersion"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报表世界字典表格数据
      datadictList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      hisVersionVal:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        keyId: null,
        keyName: null,
        classId : null,
        hisVersion:null,
      },
      queryParams2:{},
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    if(this.classId != undefined && this.classId){
      this.queryParams.classId = this.classId;
      this.queryParams.hisVersion = this.hisVersion;
      this.hisVersionVal = false;
      if (this.queryParams.hisVersion) {
        this.hisVersionVal = true;
        this.queryParams2.hisVersionVal = this.queryParams.hisVersion;
      }
      this.getList();
    }
  },
  methods: {
    /** 查询报表世界字典列表 */
    getList() {
      this.loading = true;
      listDatadict(this.queryParams).then(response => {
        this.datadictList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        classId: null,
        className: null,
        classEname: null,
        keyId: null,
        keyName: null,
        keyEname: null,
        orValidD: null,
        memo: null,
        timeMark: null,
        sta: null,
        keySeq: null,
        createPrsn: null,
        createTime: null,
        updatePrsn: null,
        updateTime: null,
        fdeleteId: null,
        rwDbFileName: null,
        rwDbVersion: null,
        rwDbStatus: null,
        rwDbAddTime: null,
        rwDbAddUser: null,
        rwDbEditTime: null,
        rwDbEditUser: null,
        rwDbDeleteReason: null,
        rwDbId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.rwDbId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
      /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
     },
    tableRowStyle({ row, rowIndex}){
        return getTableRowStyle(row,rowIndex,this.ids);
    }
  }
};
</script>
